#version 330

varying float vec4 vColor;
varying vec2 vTexCoord;
uniform sampler2d diffuse;
uniform sampler2d lightMap;
uniform vec2 resolution; 
uniform vec4 ambientColor;

void main()
{
  vec4 diffuseColor = texture2D(diffuse,texCoord);
  vec2 lightCoord = gl_FragCoord.xy / resolution.xy;
  vec4 light = texture2d(lightMap, lightCoord);
  vec3 ambient = ambientColor.rgb * ambientColor.a;
  vec3 intensity = ambient + light.rgb;
  vec3 outColor = intensity*diffuseColor.rgb;
  
  gl_FragColor = vColor*vec4(outColor,diffuseColor.a);
}


